import nump as np

def learn(self, (X, Y), (W, B) = (None, 0), lr = 1.0):
    W = np.zeros(X.shape[1]) if None == W else W
    K = 0
    # max norm from training set.
    R = np.multiply(X, X).sum(axis=1).max()

    for xi, yi in iter.imap(lambda x,y : (x, -1 if y == 0 else y) ,X, Y):
        if yi*(W.dot(xi) + B) <= 0 :
            W += lr*yi*xi
            B += lr*yi*R
            K += 1
            return W, B, K

def predict(self, X, (W, B)):
    return np.sign(X.dot(W.T) + B)
